package com.sciencep.pro.core.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dingtalk.api.request.*;
import com.dingtalk.api.response.*;
import com.sciencep.pro.common.config.Constant;
import com.sciencep.pro.common.config.SystemVariable;
import com.sciencep.pro.common.domain.ResponseResult;
import com.sciencep.pro.common.exception.CustomException;
import com.sciencep.pro.core.common.utils.SendMailUtils;
import com.sciencep.pro.core.domain.dto.dingding.DingUserDetailVO;
import com.sciencep.pro.core.domain.dto.project.ProChangeAuditTO;
import com.sciencep.pro.core.domain.dto.tokeninfo.TokenInfoTO;
import com.sciencep.pro.core.domain.dto.user.UserAttendanceTO;
import com.sciencep.pro.core.domain.dto.workdailylog.WorkLogDetailTO;
import com.sciencep.pro.core.domain.entity.*;
import com.sciencep.pro.core.service.*;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.*;

import static com.sciencep.pro.core.common.utils.UserUtil.getIfHoliday;

@Service
@Slf4j
public class TaskServiceImpl implements ITaskService {

    @Autowired
    DingDingService dingDingService;

    @Autowired
    ITokenInfoService tokenInfoService;

    @Autowired
    IDeptService deptService;

    @Autowired
    IUserService userService;

    @Autowired
    IUserDeptService userDeptService;

    @Autowired
    ITaskLogService taskLogService;

    @Autowired
    IRoleService roleService;

    @Autowired
    IUserRoleService userRoleService;

    @Autowired
    IUserAttendanceService userAttendanceService;

    @Autowired
    IUserLeaveService userLeaveService;

    @Autowired
    IUserWorkdailyLogService userWorkdailyLogService;

    @Autowired
    IProNodeService proNodeService;

    @Autowired
    IProNodeDateService proNodeDateService;

    @Autowired
    IProBaseInfoService proBaseInfoService;

    @Autowired
    IProAssignmentService proAssignmentService;

    @Autowired
    SystemVariable systemVariable;

    @Autowired
    IProcessInstanceService processInstanceService;

    @Autowired
    ICalendarInfoService calendarInfoService;

    @Autowired
    IProChangebaseService proChangebaseService;

    @Autowired
    IMailInfoService mailInfoService;

    @Autowired
    SendMailUtils   sendMailUtils;

    @Value("${dingding.wordTemplate}")
    String wordTemplate;

    String limitString = "limit 1";

    private static final String COMPLETED = "COMPLETED";

    String yMdHms = "yyyy-MM-dd HH:mm:ss";
    String yMd = "yyyy-MM-dd";

    //获取token
    public String getToken() throws CustomException, ApiException {
        TokenInfo tokenInfo = tokenInfoService.getOne(new LambdaQueryWrapper<TokenInfo>().eq(TokenInfo::getIsDel, Constant.IsDelete.NO).eq(TokenInfo::getType, 1));
        return dingDingService.getAccessToken(tokenInfo.getAppKey(), tokenInfo.getAppSecret());
    }

    //获取其它公司的token
    public List<TokenInfoTO> getOtherToken() throws CustomException, ApiException {
        List<TokenInfo> tokenInfoList = tokenInfoService.list(new LambdaQueryWrapper<TokenInfo>().eq(TokenInfo::getIsDel, Constant.IsDelete.NO).ne(TokenInfo::getType, 1));
        List<TokenInfoTO> tokenInfoTOList = new ArrayList<>();
        if (CollUtil.isNotEmpty(tokenInfoList)) {
            for (TokenInfo tokenInfo : tokenInfoList) {
                TokenInfoTO tokenInfoTO = new TokenInfoTO();
                String token = dingDingService.getAccessToken(tokenInfo.getAppKey(), tokenInfo.getAppSecret());
                tokenInfoTO.setToken(token);
                tokenInfoTO.setType(tokenInfo.getType());
                tokenInfoTOList.add(tokenInfoTO);
            }
        } else {
            throw new CustomException("请设置外包的token信息");
        }
        return tokenInfoTOList;
    }

    //获取email信息
    public MailInfo getInfo() {
        MailInfo mailInfo = mailInfoService.getOne(new LambdaQueryWrapper<MailInfo>().eq(MailInfo::getIsDel, Constant.IsDelete.NO));
        log.info("获取mail信息===> mailInfo: {} ", mailInfo);
        return mailInfo;
    }

    @Override
    public List<TaskLog> lastConcatUser() {
        List<TaskLog> taskLogList = new ArrayList<>();
        TaskLog taskLogDept = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.DEPT_TASK).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogUser = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.USER_DEPT_TASK).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogRole = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.USER_ROLE_TASK).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogResign = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.USER_RESIGN_TASK).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        taskLogList.add(taskLogDept);
        taskLogList.add(taskLogUser);
        taskLogList.add(taskLogRole);
        taskLogList.add(taskLogResign);
        return taskLogList;
    }

    @Override
    public List<TaskLog> lastConcatLog() {
        List<TaskLog> taskLogList = new ArrayList<>();
        TaskLog taskLogLeave = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.LEAVE_TASK).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogWorkDaily = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.WORK_DAILY_TASK).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogAttendance = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.ATTENDANCE_TASK).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        taskLogList.add(taskLogLeave);
        taskLogList.add(taskLogWorkDaily);
        taskLogList.add(taskLogAttendance);
        return taskLogList;
    }

    @Override
    public List<TaskLog> concatLastOtherLog() {
        List<TaskLog> taskLogList = new ArrayList<>();
        TaskLog taskLogUser = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.USER_DEPT_TASK_OTHER).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogDept = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.DEPT_TASK_OTHER).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogResign = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.USER_RESIGN_TASK_OTHER).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogLeave = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.LEAVE_TASK_OTHER).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogAttendance = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.ATTENDANCE_TASK_OTHER).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        TaskLog taskLogWorkDaily = taskLogService.getOne(new LambdaQueryWrapper<TaskLog>().
                eq(TaskLog::getTaskName, Constant.TaskName.WORK_DAILY_TASK_OTHER).
                orderByDesc(TaskLog::getTaskTime).last(limitString));
        taskLogList.add(taskLogLeave);
        taskLogList.add(taskLogAttendance);
        taskLogList.add(taskLogWorkDaily);
        taskLogList.add(taskLogUser);
        taskLogList.add(taskLogDept);
        taskLogList.add(taskLogResign);
        return taskLogList;
    }

    @Override
    @Transactional
    public List<TaskLog> concatUser() {
        List<TaskLog> taskLogList = new ArrayList<>();
        ResponseResult<Object> dataDept = this.getDeptList();
        ResponseResult<Object> dataUser = this.getUserList();
        ResponseResult<Object> dataRole = this.getUserRole();
        ResponseResult<Object> dataResign = this.getResignUser();
        taskLogList.add((TaskLog) dataDept.getData());
        taskLogList.add((TaskLog) dataUser.getData());
        taskLogList.add((TaskLog) dataRole.getData());
        taskLogList.add((TaskLog) dataResign.getData());
        return taskLogList;
    }

    @Override
    @Transactional
    public List<TaskLog> concatLog() {
        List<TaskLog> taskLogList = new ArrayList<>();
        ResponseResult<Object> dataLeave = this.getLeaveList();
        ResponseResult<Object> dataWorkDaily = this.getWorkDailyList(null);
        ResponseResult<Object> dataAttendance = this.getAttendanceList(null);
        taskLogList.add((TaskLog) dataLeave.getData());
        taskLogList.add((TaskLog) dataWorkDaily.getData());
        taskLogList.add((TaskLog) dataAttendance.getData());
        return taskLogList;
    }

    @Override
    @Transactional
    public List<TaskLog> concatLogNew(String time) {
        List<TaskLog> taskLogList = new ArrayList<>();
        ResponseResult<Object> dataLeave = this.getLeaveList();
        ResponseResult<Object> dataWorkDaily = this.getWorkDailyList(time);
        ResponseResult<Object> dataAttendance = this.getAttendanceList(time);
        taskLogList.add((TaskLog) dataLeave.getData());
        taskLogList.add((TaskLog) dataWorkDaily.getData());
        taskLogList.add((TaskLog) dataAttendance.getData());
        return taskLogList;
    }

    @Override
    public List<TaskLog> concatOtherLog() throws CustomException, ApiException {
        List<TaskLog> taskLogList = new ArrayList<>();
        ResponseResult<Object> dataUser = this.getOtherUserList();
        ResponseResult<Object> dataDept = this.getOtherDeptList();
        ResponseResult<Object> dataResign = this.getOtherResignUser();
        ResponseResult<Object> dataOtherLeave = this.getOtherLeaveList();
        ResponseResult<Object> dataAttendance = this.getOtherAttendanceList(null);
        ResponseResult<Object> dataWorkDaily = this.getOtherWorkDailyList(null);

        taskLogList.add((TaskLog) dataOtherLeave.getData());
        taskLogList.add((TaskLog) dataAttendance.getData());
        taskLogList.add((TaskLog) dataWorkDaily.getData());
        taskLogList.add((TaskLog) dataUser.getData());
        taskLogList.add((TaskLog) dataDept.getData());
        taskLogList.add((TaskLog) dataResign.getData());
        return taskLogList;
    }

    @Override
    public List<TaskLog> concatOtherLogNew(String time) throws CustomException, ApiException {
        List<TaskLog> taskLogList = new ArrayList<>();
        ResponseResult<Object> dataUser = this.getOtherUserList();
        ResponseResult<Object> dataDept = this.getOtherDeptList();
        ResponseResult<Object> dataResign = this.getOtherResignUser();
        ResponseResult<Object> dataOtherLeave = this.getOtherLeaveList();
        ResponseResult<Object> dataAttendance = this.getOtherAttendanceList(time);
        ResponseResult<Object> dataWorkDaily = this.getOtherWorkDailyList(time);

        taskLogList.add((TaskLog) dataOtherLeave.getData());
        taskLogList.add((TaskLog) dataAttendance.getData());
        taskLogList.add((TaskLog) dataWorkDaily.getData());
        taskLogList.add((TaskLog) dataUser.getData());
        taskLogList.add((TaskLog) dataDept.getData());
        taskLogList.add((TaskLog) dataResign.getData());
        return taskLogList;
    }

    @Override
    @Transactional
    public ResponseResult<Object> getDeptList() {
        try {
            List<OapiDepartmentListResponse.Department> dingDeptList = dingDingService.getDepartmentList(getToken(), null, null, null);
            List<Dept> deptList = deptService.list(new LambdaQueryWrapper<Dept>().eq(Dept::getCompanyType, 1));
            log.info("更新部门定时任务===> dingDeptList: {} ,deptList: {}", dingDeptList, deptList);
            int updateCount = 0;
            int insertCount = 0;
            for (OapiDepartmentListResponse.Department a : dingDeptList) {
                boolean isUpdate = false;
                for (Dept b : deptList) {
                    if (a.getId() == Long.parseLong(b.getDeptId())) {
                        isUpdate = true;
                        break;
                    }
                }
                Dept dept = new Dept();
                dept.setDeptId(a.getId().toString());
                dept.setDeptName(a.getName());
                dept.setCompanyType(1);
                if (a.getParentid() != null) {
                    dept.setParentId(a.getParentid().toString());
                }
                OapiDepartmentGetResponse oapiDepartmentGetResponse = dingDingService.getDepartmentDetail(a.getId().toString(), getToken());
                dept.setSort(oapiDepartmentGetResponse.getOrder().intValue());
                dept.setDeptManagerUseridList(oapiDepartmentGetResponse.getDeptManagerUseridList());
                if (isUpdate) {
                    updateCount += 1;
                    deptService.updateByDeptId(dept);
                } else {
                    insertCount += 1;
                    deptService.save(dept);
                }
            }
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.DEPT_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setInsertCount(insertCount);
            taskLog.setUpdateCount(updateCount);
            taskLog.setSuccess(Constant.IsDelete.NO);
            taskLogService.save(taskLog);
            return new ResponseResult<>().success(taskLog);
        } catch (Exception e) {
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.DEPT_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setSuccess(Constant.IsDelete.YES);
            taskLogService.save(taskLog);
            e.printStackTrace();
            try {
                sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.DEPT_TASK + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return new ResponseResult<>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
        }
    }

    @Override
    @Transactional
    public ResponseResult<Object> getUserList() {
        try {
            //获取钉钉部门id
            List<OapiDepartmentListResponse.Department> dingDeptList = dingDingService.getDepartmentList(getToken(), null, null, null);
            //获取关联表
            List<UserDept> userDeptList = userDeptService.list(new LambdaQueryWrapper<UserDept>().eq(UserDept::getCompanyType, 1));
            log.info("更新用户和部门关联表===> dingDeptList: {} ,userDeptList: {}", dingDeptList, userDeptList);
            int updateCount = 0;
            int insertCount = 0;
            for (OapiDepartmentListResponse.Department a : dingDeptList) {
                //获取钉钉部门下的用户
                OapiUserSimplelistRequest oapiUserSimplelistRequest = new OapiUserSimplelistRequest();
                oapiUserSimplelistRequest.setDepartmentId(a.getId());
                List<OapiUserSimplelistResponse.Userlist> dingUserList = dingDingService.getUserSimplelist(oapiUserSimplelistRequest, getToken());

                //获取部门下的用户
                List<User> userList = userService.list();
                //操作用户表
                for (OapiUserSimplelistResponse.Userlist dingUser : dingUserList) {
                    boolean isUserUpdate = false;
                    for (User u : userList) {
                        if (dingUser.getUserid().equals(u.getUserId())) {
                            isUserUpdate = true;
                            break;
                        }
                    }
                    DingUserDetailVO dingUserDetailVO = dingDingService.getUserDetailByUserid(getToken(), dingUser.getUserid());
                    User user = new User();
                    user.setUnionId(dingUserDetailVO.getUnionid());
                    user.setUserId(dingUserDetailVO.getUserid());
                    user.setUserName(dingUserDetailVO.getName());
                    user.setMobile(dingUserDetailVO.getMobile());
                    user.setEmail(dingUserDetailVO.getEmail());
                    user.setPosition(dingUserDetailVO.getPosition());
                    user.setAvatar(dingUserDetailVO.getAvatar());
                    user.setHiredDate(dingUserDetailVO.getHiredDate());
                    user.setJobNumber(dingUserDetailVO.getJobnumber());
                    user.setIsAdmin(dingUserDetailVO.getIsAdmin().equals(true) ? 1 : 0);
                    user.setIsSenior(dingUserDetailVO.getIsSenior().equals(true) ? 1 : 0);
                    user.setWorkPlace(dingUserDetailVO.getWorkplace());
                    user.setIsResign(Constant.IsDelete.YES);
                    user.setCompanyType(1);
                    if (isUserUpdate) {
                        updateCount += 1;
                        userService.updateUser(user);
                    } else {
                        insertCount += 1;
                        userService.save(user);
                    }
                }
                //删除操作用户部门关联表多余的数据
                List<UserDept> userDeptListDel = userDeptService.list(new LambdaQueryWrapper<UserDept>().eq(UserDept::getDeptId, a.getId()).eq(UserDept::getCompanyType, 1));
                for (UserDept userDept : userDeptListDel) {
                    boolean delUserDept = false;
                    //操作用户部门关联表
                    for (OapiUserSimplelistResponse.Userlist dingUser : dingUserList) {
                        if (dingUser.getUserid().equals(userDept.getUserId()) && a.getId() == Long.parseLong(userDept.getDeptId())) {
                            delUserDept = true;
                            break;
                        }
                    }
                    //删除
                    if (!delUserDept) {
                        updateCount += 1;
                        userDeptService.delUserDept(userDept);
                    }
                }

                //删除操作用户部门关联表(非主公司的成员删除)
                List<UserDept> userDeptListDel1 = userDeptService.list(new LambdaQueryWrapper<UserDept>().ne(UserDept::getCompanyType, 1));
                for (UserDept userDept : userDeptListDel1) {
                    boolean delUserDept = false;
                    //操作用户部门关联表
                    for (OapiUserSimplelistResponse.Userlist dingUser : dingUserList) {
                        if (dingUser.getUserid().equals(userDept.getUserId())) {
                            delUserDept = true;
                            break;
                        }
                    }
                    //删除
                    if (delUserDept) {
                        updateCount += 1;
                        userDeptService.removeById(userDept.getId());
                    }
                }


                //操作用户部门关联表
                for (OapiUserSimplelistResponse.Userlist dingUser : dingUserList) {
                    boolean isUserDeptUpdate = false;
                    for (UserDept userDept : userDeptList) {
                        if (dingUser.getUserid().equals(userDept.getUserId()) && a.getId() == Long.parseLong(userDept.getDeptId())) {
                            isUserDeptUpdate = true;
                            break;
                        }
                    }
                    UserDept userDept = new UserDept();
                    userDept.setUserId(dingUser.getUserid());
                    userDept.setDeptId(a.getId().toString());
                    userDept.setCompanyType(1);
                    if (isUserDeptUpdate) {
                        updateCount += 1;
                        userDeptService.update(userDept, new LambdaQueryWrapper<UserDept>().eq(UserDept::getUserId, dingUser.getUserid()).eq(UserDept::getDeptId, a.getId()));
                    } else {
                        insertCount += 1;
                        userDeptService.save(userDept);
                    }
                }


            }
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.USER_DEPT_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setInsertCount(insertCount);
            taskLog.setUpdateCount(updateCount);
            taskLog.setSuccess(Constant.IsDelete.NO);
            taskLogService.save(taskLog);
            return new ResponseResult<Object>().success(taskLog);
        } catch (Exception e) {
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.USER_DEPT_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setSuccess(Constant.IsDelete.YES);
            taskLogService.save(taskLog);
            e.printStackTrace();
            try {
                sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.USER_DEPT_TASK + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
        }
    }

    @Override
    @Transactional
    public ResponseResult<Object> getUserRole() {
        try {
            Long size = 200L;
            Long offSet = 0L;
            int updateRoleCount = 0;
            int insertRoleCount = 0;
            OapiRoleListRequest roleListRequest = new OapiRoleListRequest();
            roleListRequest.setSize(size);
            roleListRequest.setOffset(offSet);
            //获取角色列表
            OapiRoleListResponse.PageVo dingRoleList = dingDingService.getRoleListPage(roleListRequest, getToken());
            //钉钉接口含有分页,查出所有值
            while (dingRoleList.getHasMore().equals(true)) {
                roleListRequest.setSize(size);
                offSet += 1L;
                roleListRequest.setOffset(offSet);
                OapiRoleListResponse.PageVo newDingRoleList = dingDingService.getRoleListPage(roleListRequest, getToken());
                dingRoleList.getList().addAll(newDingRoleList.getList());
                dingRoleList.setHasMore(newDingRoleList.getHasMore());
            }
            //所有角色
            List<Role> roleList = roleService.list();
            log.info("更新角色和用户关联表===> dingRoleList: {} ,roleList: {}", dingRoleList, roleList);
            //删除系统中多余的角色
            for (Role role : roleList) {
                boolean delGroup = false;
                boolean delRole = false;
                for (OapiRoleListResponse.OpenRoleGroup dingRole : dingRoleList.getList()) {
                    if (role.getGroupId().equals(dingRole.getGroupId().toString())) {
                        delGroup = true;
                        for (OapiRoleListResponse.OpenRole dingDingRole : dingRole.getRoles()) {
                            if (role.getRoleId().equals(dingDingRole.getId().toString())) {
                                delRole = true;
                                break;
                            }
                        }
                        if (!delRole) {
                            roleService.delRole(role.getRoleId());
                        }
                    }
                }
                if (!delGroup) {
                    roleService.delGroup(role.getGroupId());
                }
            }
            for (OapiRoleListResponse.OpenRoleGroup dingRole : dingRoleList.getList()) {
                //更新角色表
                for (OapiRoleListResponse.OpenRole dingDingRole : dingRole.getRoles()) {
                    boolean isRoleUpdate = false;
                    for (Role role : roleList) {
                        if (role.getRoleId().equals(dingDingRole.getId().toString()) && role.getGroupId().equals(dingRole.getGroupId().toString())) {
                            isRoleUpdate = true;
                            break;
                        }
                    }
                    Role role = new Role();
                    role.setRoleId(dingDingRole.getId().toString());
                    role.setRoleName(dingDingRole.getName());
                    role.setGroupId(dingRole.getGroupId().toString());
                    role.setGroupName(dingRole.getName());
                    if (isRoleUpdate) {
                        updateRoleCount += 1;
                        roleService.update(role, new LambdaQueryWrapper<Role>().eq(Role::getRoleId, dingDingRole.getId()).eq(Role::getGroupId, dingRole.getGroupId()));
                    } else {
                        insertRoleCount += 1;
                        roleService.save(role);
                    }

                    //更新角色用户关联表
                    List<UserRole> userRoleList = userRoleService.list(new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId, dingDingRole.getId()));
                    Long sizeUser = 100L;
                    Long offSetUser = 0L;
                    OapiRoleSimplelistRequest request = new OapiRoleSimplelistRequest();
                    request.setRoleId(dingDingRole.getId());
                    request.setOffset(offSetUser);
                    request.setSize(sizeUser);
                    OapiRoleSimplelistResponse.PageVo dingUserRoleList = dingDingService.getRoleSimpleList(request, getToken());
                    //钉钉接口含有分页,查出所有值
                    while (dingUserRoleList.getHasMore().equals(true)) {
                        request.setSize(sizeUser);
                        offSetUser += 1L;
                        request.setOffset(offSetUser);
                        OapiRoleSimplelistResponse.PageVo newDingUserRoleList = dingDingService.getRoleSimpleList(request, getToken());
                        dingUserRoleList.getList().addAll(newDingUserRoleList.getList());
                        dingUserRoleList.setHasMore(newDingUserRoleList.getHasMore());
                    }

                    //删除用户角色关联表多余的数据
                    for (UserRole userRole : userRoleList) {
                        boolean delUserRole = false;
                        //操作用户角色关联表
                        for (OapiRoleSimplelistResponse.OpenEmpSimple dingUserRole : dingUserRoleList.getList()) {
                            if (dingUserRole.getUserid().equals(userRole.getUserId()) && dingDingRole.getId().toString().equals(userRole.getRoleId())) {
                                delUserRole = true;
                                break;
                            }
                        }
                        //删除
                        if (!delUserRole) {
                            updateRoleCount += 1;
                            userRoleService.delUserRole(userRole);
                        }
                    }

                    for (OapiRoleSimplelistResponse.OpenEmpSimple dingUserRole : dingUserRoleList.getList()) {
                        boolean isUserRoleUpdate = false;
                        for (UserRole userRole : userRoleList) {
                            if (userRole.getUserId().equals(dingUserRole.getUserid()) && userRole.getRoleId().equals(dingDingRole.getId().toString())) {
                                isUserRoleUpdate = true;
                                break;
                            }
                        }
                        UserRole userRole = new UserRole();
                        userRole.setUserId(dingUserRole.getUserid());
                        userRole.setRoleId(dingDingRole.getId().toString());
                        if (isUserRoleUpdate) {
                            updateRoleCount += 1;
                            userRoleService.update(userRole, new LambdaQueryWrapper<UserRole>().eq(UserRole::getRoleId, dingDingRole.getId()).eq(UserRole::getUserId, dingUserRole.getUserid()));
                        } else {
                            insertRoleCount += 1;
                            userRoleService.save(userRole);
                        }
                    }

                }

            }

            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.USER_ROLE_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setInsertCount(insertRoleCount);
            taskLog.setUpdateCount(updateRoleCount);
            taskLog.setSuccess(Constant.IsDelete.NO);
            taskLogService.save(taskLog);
            return new ResponseResult<Object>().success(taskLog);
        } catch (Exception e) {
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.USER_ROLE_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setSuccess(Constant.IsDelete.YES);
            taskLogService.save(taskLog);
            e.printStackTrace();
            try {
                sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.USER_ROLE_TASK + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
        }
    }

    @Override
    @Transactional
    public ResponseResult<Object> getResignUser() {
        try {
            Long size = 20L;
            Long offSet = 1L;
            Integer updateCount = 0;
            Integer insertCount = 0;
            //查询所有离职用户的id
            OapiSmartworkHrmEmployeeQuerydimissionResponse.Paginator resignUserList = dingDingService.getEmployeeDimission(offSet, size, getToken());
            while (resignUserList.getNextCursor() != null) {
                offSet += 1;
                OapiSmartworkHrmEmployeeQuerydimissionResponse.Paginator newResignUserList = dingDingService.getEmployeeDimission(offSet, size, getToken());
                resignUserList.getDataList().addAll(newResignUserList.getDataList());
                resignUserList.setNextCursor(newResignUserList.getNextCursor());
            }
            //更新离职用户
            List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, 1));
            log.info("更新离职员工定时任务===> resignUserList: {} ,userList: {}", resignUserList, userList);
            for (String str : resignUserList.getDataList()) {
                for (User user : userList) {
                    if (str.equals(user.getUserId())) {
                        updateCount += 1;
                        user.setIsResign(Constant.IsDelete.NO);
                        userService.update(user, new LambdaQueryWrapper<User>().eq(User::getId, user.getId()));
                    }
                }
            }

            //更新员工类型
            List<User> userLists = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, 1).eq(User::getIsResign, 1));
            //钉钉员工状态获取(userId最多传50个)
            List<User> dingUserLists = new ArrayList<>();
            dingUserLists.addAll(userLists);
            List<User> dingUserLists1;
            List<OapiSmartworkHrmEmployeeListResponse.EmpFieldInfoVO> dingEmployeeList = new ArrayList<>();
            while (CollUtil.isNotEmpty(dingUserLists)) {

                if (dingUserLists.size() <= 50) {
                    dingUserLists1 = dingUserLists.subList(0, dingUserLists.size());
                } else {
                    dingUserLists1 = dingUserLists.subList(0, 50);
                }
                StringBuilder userString = new StringBuilder();
                for (User user : dingUserLists1) {
                    userString.append(user.getUserId() + ",");
                }
                List<OapiSmartworkHrmEmployeeListResponse.EmpFieldInfoVO> dingEmployee = dingDingService.getHrmEmployeeList(userString.toString(), null, getToken());
                dingEmployeeList.addAll(dingEmployee);
                //删除list前50条的数据
                Iterator<User> iterator = dingUserLists.iterator();
                int i = 0;
                while (iterator.hasNext()) {
                    iterator.next();//next（）取出元素
                    if (i <= 49) {
                        iterator.remove(); //remove方法会删除使用next()方法返回 的元素
                    }
                    i++;
                }
            }
            for (User user : userLists) {
                for (OapiSmartworkHrmEmployeeListResponse.EmpFieldInfoVO employee : dingEmployeeList) {
                    if (employee.getUserid().equals(user.getUserId())) {
                        boolean isUpdate = false;
                        User user1 = new User();
                        for (OapiSmartworkHrmEmployeeListResponse.EmpFieldVO empField : employee.getFieldList()) {
                            if (empField.getFieldCode().equals("sys01-employeeType")) {
                                user1.setEmployeeType(empField.getLabel());
                                updateCount += 1;
                                isUpdate = true;
                            }
                            if (empField.getFieldCode().equals("sys01-employeeStatus")) {
                                user1.setEmployeeStatus(empField.getLabel());
                                isUpdate = true;
                            }
                        }
                        if (isUpdate) {
                            userService.update(user1, new LambdaQueryWrapper<User>().eq(User::getUserId, user.getUserId()));
                        }
                    }
                }
            }

            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.USER_RESIGN_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setInsertCount(insertCount);
            taskLog.setUpdateCount(updateCount);
            taskLog.setSuccess(Constant.IsDelete.NO);
            taskLogService.save(taskLog);
            return new ResponseResult<Object>().success(taskLog);
        } catch (Exception e) {
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.USER_RESIGN_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setSuccess(Constant.IsDelete.YES);
            taskLogService.save(taskLog);
            e.printStackTrace();
            try {
                sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.USER_RESIGN_TASK + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
        }
    }

    @Override
    @Transactional
    public ResponseResult<Object> getAttendanceList(String time) {
        try {
            SimpleDateFormat sdfFrom = new SimpleDateFormat(yMdHms);
            SimpleDateFormat sdfEnd = new SimpleDateFormat(yMdHms);
            SimpleDateFormat sdfymd = new SimpleDateFormat(yMd);
            Date dateFrom;
            Date dateEnd;
            if(time == null){
                //开始时间
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                //往前推1天
                //calendar.add(Calendar.DATE, -1);
                dateFrom = calendar.getTime();

                //结束时间
                Calendar calendarEnd = Calendar.getInstance();
                dateEnd = calendarEnd.getTime();
            }else{
                dateFrom = getStartOfDay(sdfymd.parse(time));
                dateEnd = getEndOfDay(sdfymd.parse(time));
            }


            List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, 1));
            log.info("更新考勤定时任务===> userList: {},dateFrom :{},dateEnd:{}", userList, sdfFrom.format(dateFrom), sdfEnd.format(dateEnd));
            int insertCount = 0;
            int updateCount = 0;
            for (User u : userList) {

                OapiAttendanceListRequest request = new OapiAttendanceListRequest();
                request.setWorkDateFrom(sdfFrom.format(dateFrom));
                request.setWorkDateTo(sdfEnd.format(dateEnd));
                List<String> str = new ArrayList<>();
                str.add(u.getUserId());
                request.setUserIdList(str);
                request.setOffset(0L);
                request.setLimit(2L);
                List<OapiAttendanceListResponse.Recordresult> dingAttendanceList = dingDingService.getAttendanceList(request, getToken());

                if (CollUtil.isNotEmpty(dingAttendanceList)) {

                    UserAttendanceTO userAttendanceTO = new UserAttendanceTO();
                    userAttendanceTO.setUserId(u.getUserId());
                    userAttendanceTO.setUserName(u.getUserName());
                    userAttendanceTO.setCreateDate(new Date());
                    for (OapiAttendanceListResponse.Recordresult dingAttendance : dingAttendanceList) {
                        userAttendanceTO.setDutyDate(dingAttendance.getWorkDate());
                        switch (dingAttendance.getCheckType()) {
                            case "OnDuty":
                                userAttendanceTO.setOnDutyTimeResult(dingAttendance.getTimeResult());
                                userAttendanceTO.setOnDuty(dingAttendance.getUserCheckTime());
                                break;
                            case "OffDuty":
                            default:
                                userAttendanceTO.setOffDutyTimeResult(dingAttendance.getTimeResult());
                                userAttendanceTO.setOffDuty(dingAttendance.getUserCheckTime());
                                break;
                        }
                    }
                    //查询是否有当天的记录
                    SimpleDateFormat sdf = new SimpleDateFormat(yMd);
                    UserAttendance userAttendance = userAttendanceService.getOne(new LambdaQueryWrapper<UserAttendance>().eq(UserAttendance::getUserId, u.getUserId()).eq(UserAttendance::getDutyDate, sdf.format(userAttendanceTO.getDutyDate())));
                    if (null == userAttendance) {
                        insertCount += 1;
                        userAttendanceService.saveUserAttendance(userAttendanceTO);
                    } else {
                        updateCount += 1;
                        userAttendanceTO.setModifyDate(new Date());
                        userAttendanceService.updateUserAttendance(userAttendanceTO);
                    }

                }

            }
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.ATTENDANCE_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setInsertCount(insertCount);
            taskLog.setUpdateCount(updateCount);
            taskLog.setSuccess(Constant.IsDelete.NO);
            taskLogService.save(taskLog);
            return new ResponseResult<Object>().success(taskLog);
        } catch (Exception e) {
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.ATTENDANCE_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setSuccess(Constant.IsDelete.YES);
            taskLogService.save(taskLog);
            e.printStackTrace();
            try {
                sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.ATTENDANCE_TASK + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
        }
    }

    @Override
    @Transactional
    public ResponseResult<Object> getLeaveList() {
        try {
            //开始时间
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.HOUR_OF_DAY, 0);
            calendar.set(Calendar.MINUTE, 0);
            calendar.set(Calendar.SECOND, 0);
            //往前推7天
            calendar.add(Calendar.DATE, -7);
            Date dateFrom = calendar.getTime();
            SimpleDateFormat sdfFrom = new SimpleDateFormat(yMdHms);

            //结束时间
            Calendar calendarEnd = Calendar.getInstance();
            Date dateEnd = calendarEnd.getTime();
            SimpleDateFormat sdfEnd = new SimpleDateFormat(yMdHms);

            Long offSet = 0L;
            Long size = 10L;
            List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, 1));
            log.info("更新请假定时任务===> userList: {},dateFrom :{},dateEnd:{}", userList, sdfFrom.format(dateFrom), sdfEnd.format(dateEnd));
            int insertCount = 0;
            for (User u : userList) {
                OapiAttendanceGetleavestatusRequest request = new OapiAttendanceGetleavestatusRequest();
                request.setStartTime(sdfFrom.parse(sdfFrom.format(dateFrom)).getTime());
                request.setEndTime(sdfEnd.parse(sdfFrom.format(dateEnd)).getTime());
                request.setOffset(offSet);
                request.setSize(size);
                request.setUseridList(u.getUserId());
                OapiAttendanceGetleavestatusResponse.LeaveStatusListVO dingLeave = dingDingService.getLeaveStatus(request, getToken());

                //钉钉接口含有分页,查出所有值
                while (dingLeave.getHasMore().equals(true)) {
                    request.setSize(size);
                    offSet += 1L;
                    request.setOffset(offSet);
                    OapiAttendanceGetleavestatusResponse.LeaveStatusListVO newDingLeave = dingDingService.getLeaveStatus(request, getToken());
                    dingLeave.getLeaveStatus().addAll(newDingLeave.getLeaveStatus());
                    dingLeave.setHasMore(newDingLeave.getHasMore());
                }

                //删除当前用户7天前到现在的数据
                userLeaveService.delLeave(u.getUserId(), dateFrom, dateEnd);

                if (CollUtil.isNotEmpty(dingLeave.getLeaveStatus())) {
                    List<UserLeave> userLeaveList = new ArrayList<>();
                    for (OapiAttendanceGetleavestatusResponse.LeaveStatusVO leave : dingLeave.getLeaveStatus()) {
                        UserLeave userLeave = new UserLeave();
                        userLeave.setUserId(u.getUserId());
                        userLeave.setUserName(u.getUserName());
                        //时间戳转date
                        SimpleDateFormat sdf = new SimpleDateFormat(yMdHms);
                        Date dateB = new Date(leave.getStartTime());
                        String dateBeginTime = sdf.format(dateB);
                        Date dateE = new Date(leave.getEndTime());
                        String dateEndTime = sdf.format(dateE);

                        userLeave.setLeaveBeginTime(sdf.parse(dateBeginTime));
                        userLeave.setLeaveEndTime(sdf.parse(dateEndTime));
                        userLeaveList.add(userLeave);
                        insertCount += 1;
                    }

                    if (CollUtil.isNotEmpty(userLeaveList)) {
                        userLeaveService.saveBatch(userLeaveList);
                    }
                }
            }
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.LEAVE_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setInsertCount(insertCount);
            taskLog.setSuccess(Constant.IsDelete.NO);
            taskLogService.save(taskLog);
            return new ResponseResult<Object>().success(taskLog);
        } catch (Exception e) {
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.LEAVE_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setSuccess(Constant.IsDelete.YES);
            taskLogService.save(taskLog);
            e.printStackTrace();
            try {
                sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.LEAVE_TASK + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
        }
    }

    // 获得某天最大时间 2020-02-19 23:59:59
    public static Date getEndOfDay(Date date) {
        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());;
        LocalDateTime endOfDay = localDateTime.with(LocalTime.MAX);
        return Date.from(endOfDay.atZone(ZoneId.systemDefault()).toInstant());
    }

    // 获得某天最小时间 2020-02-17 00:00:00
    public static Date getStartOfDay(Date date) {
        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
        LocalDateTime startOfDay = localDateTime.with(LocalTime.MIN);
        return Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
    }

    @Override
    @Transactional
    public ResponseResult<Object> getWorkDailyList(String time) {
        try {
            SimpleDateFormat sdfFrom = new SimpleDateFormat(yMdHms);
            SimpleDateFormat sdfEnd = new SimpleDateFormat(yMdHms);
            SimpleDateFormat sdfymd = new SimpleDateFormat(yMd);
            Date dateFrom;
            Date dateEnd;
            if(time == null){
                //开始时间
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                //往前推1天
                calendar.add(Calendar.DATE, -1);
                dateFrom = calendar.getTime();

                //结束时间
                Calendar calendarEnd = Calendar.getInstance();
                dateEnd = calendarEnd.getTime();
            }else{
                dateFrom = getStartOfDay(sdfymd.parse(time));
                dateEnd = getEndOfDay(sdfymd.parse(time));
            }

            int insertCount = 0;
            int updateCount = 0;
            OapiReportListRequest request = new OapiReportListRequest();
            request.setStartTime(sdfFrom.parse(sdfFrom.format(dateFrom)).getTime());
            request.setEndTime(sdfEnd.parse(sdfFrom.format(dateEnd)).getTime());
            request.setTemplateName(wordTemplate);
            request.setCursor(0L);
            request.setSize(20L);
            OapiReportListResponse.PageVo dingWorkDaily = dingDingService.getReportList(request, getToken());
            log.info("while (dingWorkDaily.getHasMore().equals(true)) :", JSON.toJSONString((dingWorkDaily.getHasMore().equals(true))));
            while (dingWorkDaily.getHasMore().equals(true)) {
                log.info(" while内第一行 ===> dingWorkDaily.getNextCursor: {},", JSON.toJSONString(((dingWorkDaily.getNextCursor()))));
                request.setCursor(dingWorkDaily.getNextCursor());
                log.info(" while内第二行 ===> request: {},",JSON.toJSONString((request)));
                OapiReportListResponse.PageVo newDingWorkDaily = dingDingService.getReportList(request, getToken());
                log.info(" while内第三行 ===> newDingWorkDaily.getNextCursor: {},",JSON.toJSONString((newDingWorkDaily.getNextCursor())));
                dingWorkDaily.setHasMore(newDingWorkDaily.getHasMore());
                log.info(" while内第三行1 ===> newDingWorkDaily.getHasMore(): {},",JSON.toJSONString((newDingWorkDaily.getHasMore())));
                log.info(" while内第三行1 ===> dingWorkDaily.getHasMore(): {},",JSON.toJSONString(dingWorkDaily.getHasMore()));
                dingWorkDaily.setNextCursor(newDingWorkDaily.getNextCursor());
                log.info(" while内第三行2 ===> dingWorkDaily.getNextCursor(): {},",JSON.toJSONString(dingWorkDaily.getNextCursor()));
                dingWorkDaily.getDataList().addAll(newDingWorkDaily.getDataList());
                log.info(" while内第四行 ===> newDingWorkDaily.getHasMore(): {},",JSON.toJSONString((dingWorkDaily.getDataList())));
            }
            List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, 1));
            log.info("更新用户日志信息任务===> userList: {},dingWorkDaily: {},dateFrom :{},dateEnd:{}", userList, dingWorkDaily, sdfFrom.format(dateFrom), sdfEnd.format(dateEnd));
            if (CollUtil.isNotEmpty(dingWorkDaily.getDataList())) {
                //1.在插入日志表时，根据工作时间，项目编号，去项目节点周期表pro_node_date中查找该日志所处在的项目节点id，并更新到日志表user_workdaily_log的项目节点id，nodeId字段。
                //2.再根据用户id，项目编号，节点id在项目人员分配表中获取项目角色ID：proroleId，并更新到日志表user_workdaily_log的项目角色ID，proroleId字段。
                for (OapiReportListResponse.ReportOapiVo dingWork : dingWorkDaily.getDataList()) {
                    for (User u : userList) {
                        if (u.getUserId().equals(dingWork.getCreatorId())) {
                            WorkLogDetailTO workLogDetailTO = new WorkLogDetailTO();
                            //获取Contents值并且匹配
                            for (OapiReportListResponse.JsonObject contents : dingWork.getContents()) {
                                //工作日期
                                if (contents.getKey().equals(systemVariable.getWorkDate())) {
                                    SimpleDateFormat sdf = new SimpleDateFormat(yMd);
                                    workLogDetailTO.setWorkDate(sdf.parse(contents.getValue()));
                                }
                                //投入人天
                                else if (contents.getKey().equals(systemVariable.getPutinDaily())) {
                                    workLogDetailTO.setPutinDaily(new BigDecimal(contents.getValue()));
                                }
                                //所属部门
                                else if (contents.getKey().equals(systemVariable.getWorkDept())) {
                                    workLogDetailTO.setDeptName(contents.getValue());
                                }
                                //项目
                                else if (contents.getKey().equals(systemVariable.getProName())) {
                                    workLogDetailTO.setProName(contents.getValue());
                                }
                                //开发节点
                                else if (contents.getKey().equals(systemVariable.getNodeName())) {
                                    workLogDetailTO.setDevPoint(contents.getValue());
                                }
                                //绩效人天
                                else if (contents.getKey().equals(systemVariable.getPerformanceDaily())) {
                                    workLogDetailTO.setPerformanceDaily(new BigDecimal(contents.getValue()));
                                }
                                //今日工作
                                else if (contents.getKey().equals(systemVariable.getDailyLog())) {
                                    workLogDetailTO.setDailyLog(contents.getValue());
                                }
                                //备注
                                else if (contents.getKey().equals(systemVariable.getRemark())) {
                                    workLogDetailTO.setRemark(contents.getValue());
                                }
                                //明日计划
                                else if (contents.getKey().equals(systemVariable.getTomorrowPlan())) {
                                    workLogDetailTO.setTomorrowPlan(contents.getValue());
                                }
                            }

                            UserWorkdailyLog userWorkdailyLog = new UserWorkdailyLog();
                            userWorkdailyLog.setUserId(u.getUserId());
                            userWorkdailyLog.setUserName(u.getUserName());
                            if (null != deptService.getOne(new LambdaQueryWrapper<Dept>().eq(Dept::getDeptName, workLogDetailTO.getDeptName()))) {
                                Dept dept = deptService.getOne(new LambdaQueryWrapper<Dept>().eq(Dept::getDeptName, workLogDetailTO.getDeptName()));
                                userWorkdailyLog.setUserDept(dept.getDeptId());
                                userWorkdailyLog.setDeptName(dept.getDeptName());
                            }
                            if (StringUtils.isNotBlank(workLogDetailTO.getProName())) {
                                try {
                                    userWorkdailyLog.setProNo(workLogDetailTO.getProName().substring(workLogDetailTO.getProName().lastIndexOf("(") + 1, workLogDetailTO.getProName().lastIndexOf(")")));//项目编号
                                    userWorkdailyLog.setProName(workLogDetailTO.getProName().substring(0, workLogDetailTO.getProName().lastIndexOf("(")));//项目名称
                                } catch (Exception e) {
                                    sendMailUtils.send(getInfo().getSendTo(), "日志模版中,项目 " + workLogDetailTO.getProName() + " 名称格式有误，请检查日志模版中项目选项的配置！",
                                            Constant.TaskMessage.DAILY_LOG_FAILURE,
                                            false, null);
                                    continue;
                                }
                            }
                            if (null != proBaseInfoService.getOne(new LambdaQueryWrapper<ProBaseInfo>().eq(ProBaseInfo::getProCode, userWorkdailyLog.getProNo()))) {
                                ProBaseInfo proBaseInfo = proBaseInfoService.getOne(new LambdaQueryWrapper<ProBaseInfo>().eq(ProBaseInfo::getProCode, userWorkdailyLog.getProNo()));
                                if (null != proNodeDateService.getProNodeId(proBaseInfo.getId(), workLogDetailTO.getWorkDate())) {
                                    ProNodeDate proNodeDate = proNodeDateService.getProNodeId(proBaseInfo.getId(), workLogDetailTO.getWorkDate());
                                    userWorkdailyLog.setNodeId(Long.valueOf(proNodeDate.getProNodeId()));//项目节点
                                    ProNode proNode = proNodeService.getOne(new LambdaQueryWrapper<ProNode>().eq(ProNode::getId, proNodeDate.getProNodeId()));
                                    userWorkdailyLog.setNodeName(proNode.getNodeName());//项目节点名称
                                }
                                if (null != proAssignmentService.getOne
                                        (new LambdaQueryWrapper<ProAssignment>().eq(ProAssignment::getUserId, userWorkdailyLog.getUserId()).
                                                eq(ProAssignment::getProId, proBaseInfo.getId()).
                                                eq(ProAssignment::getNodeId, userWorkdailyLog.getNodeId()))) {
                                    ProAssignment proAssignment = proAssignmentService.getOne
                                            (new LambdaQueryWrapper<ProAssignment>().eq(ProAssignment::getUserId, userWorkdailyLog.getUserId()).
                                                    eq(ProAssignment::getProId, proBaseInfo.getId()).
                                                    eq(ProAssignment::getNodeId, userWorkdailyLog.getNodeId()));
                                    userWorkdailyLog.setProroleId(proAssignment.getProroleId());//项目角色
                                }
                            } else {
                                if (!userWorkdailyLog.getProNo().equals("OTHER0001")) {
                                    sendMailUtils.send(getInfo().getSendTo(), "日志模版中" + workLogDetailTO.getProName() + "不存在，请检查日志模版中项目选项的配置！",
                                            Constant.TaskMessage.DAILY_LOG_FAILURE,
                                            false, null);
                                    continue;
                                }
                            }
                            userWorkdailyLog.setDevPoint(workLogDetailTO.getDevPoint());
                            userWorkdailyLog.setWorkDate(workLogDetailTO.getWorkDate());
                            userWorkdailyLog.setPutinDaily(workLogDetailTO.getPutinDaily());
                            userWorkdailyLog.setPerformanceDaily(workLogDetailTO.getPerformanceDaily());
                            userWorkdailyLog.setDailyLog(workLogDetailTO.getDailyLog());
                            userWorkdailyLog.setRemark(workLogDetailTO.getRemark());
                            userWorkdailyLog.setTomorrowPlan(workLogDetailTO.getTomorrowPlan());
                            userWorkdailyLog.setTemplateName(dingWork.getTemplateName());
                            userWorkdailyLog.setSubmitTime(new Date(dingWork.getCreateTime()));

                            //查询是否有记录
                            int record = userWorkdailyLogService.selectCount(userWorkdailyLog);
                            log.info("===========================================record:"+record+"===========================================");
                            if (record == 0) {
                                insertCount += 1;
                                userWorkdailyLogService.save(userWorkdailyLog);
                            } else {
                                int isReview = userWorkdailyLogService.isReview(userWorkdailyLog);
                                if (isReview == 0) {
                                    updateCount += 1;
                                    userWorkdailyLogService.update(userWorkdailyLog, new LambdaQueryWrapper<UserWorkdailyLog>().eq(UserWorkdailyLog::getUserId,userWorkdailyLog.getUserId()).eq(UserWorkdailyLog::getSubmitTime, userWorkdailyLog.getSubmitTime()));
                                }
                            }
                        }
                    }
                }

            }

            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.WORK_DAILY_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setInsertCount(insertCount);
            taskLog.setUpdateCount(updateCount);
            taskLog.setSuccess(Constant.IsDelete.NO);
            taskLogService.save(taskLog);
            return new ResponseResult<Object>().success(taskLog);
        } catch (Exception e) {
            TaskLog taskLog = new TaskLog();
            taskLog.setTaskName(Constant.TaskName.WORK_DAILY_TASK);
            taskLog.setTaskTime(new Date());
            taskLog.setSuccess(Constant.IsDelete.YES);
            taskLogService.save(taskLog);
            e.printStackTrace();
            try {
                sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.WORK_DAILY_TASK + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
        }
    }

    @Override
    public void getProcessingResult() {


        // 1. 获取所有未完成的审批示例
        List<ProcessInstance> processInstances = processInstanceService.
                list(new LambdaQueryWrapper<ProcessInstance>().ne(ProcessInstance::getStatus, COMPLETED));
        for (ProcessInstance processInstance : processInstances) {

            try {
                OapiProcessinstanceGetResponse.ProcessInstanceTopVo vo = dingDingService
                        .getProcessResult(processInstance.getInstanceId(), getToken());

                if (processInstance.getType().equals(1)) {
                    ProBaseInfo proBaseInfo = proBaseInfoService.getById(processInstance.getObjId());
                    if (proBaseInfo == null) {
                        continue;
                    }
                    processInstance.setStatus(vo.getStatus());

                    if (vo.getStatus().equals(COMPLETED)) {
                        Integer result = vo.getResult().equals("agree") ? 6 : 5;
                        proBaseInfo.setProStatus(result);
                        processInstance.setResult(result);
                    }
                    proBaseInfoService.updateById(proBaseInfo);
                    processInstanceService.updateById(processInstance);
                }
                if (processInstance.getType().equals(2)) {
                    ProChangebase proChangebase = proChangebaseService.getOne(new LambdaQueryWrapper<ProChangebase>().eq(ProChangebase::getChangeNo, processInstance.getObjId()));
                    if (proChangebase == null) {
                        continue;
                    }
                    processInstance.setStatus(vo.getStatus());

                    if (vo.getStatus().equals(COMPLETED)) {
                        Integer result = vo.getResult().equals("agree") ? 1 : 2;
                        proChangebase.setChangeStatus(result);
                        processInstance.setResult(result);
                        if (result == 1) {
                            ProChangeAuditTO proChangeAuditTO = new ProChangeAuditTO();
                            proChangeAuditTO.setChangeStatus(result).setApproOpinions("同意").setChangeNo(proChangebase.getChangeNo());
                            proBaseInfoService.auditChange(proChangeAuditTO, null);
                        }
                    }
                    proChangebaseService.updateById(proChangebase);
                    processInstanceService.updateById(processInstance);


                }
            } catch (Exception e) {
                e.printStackTrace();
                log.error("审批定时任务出错 {}", e.getMessage());
            }
        }
    }

    @Override
    public ResponseResult<Object> getCalendar() throws ParseException {
        List<CalendarInfo> listCalendar = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();

        calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR));// 默认为当年
        List<CalendarInfo> calendarInfoList = calendarInfoService.list(new LambdaQueryWrapper<CalendarInfo>().last("WHERE DATE_FORMAT(date,'%Y')  = " + calendar.get(Calendar.YEAR)));
        //更新当年所有数据
        if (CollUtil.isNotEmpty(calendarInfoList)) {
            //获取12个月
            for (int month = 1; month <= 12; month++) {
                calendar.set(Calendar.MONTH, month - 1);// 设置月份
                calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为当月第一天
                int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);// 当月最大天数
                for (int i = 0; i < daySize; i++) {
                    String format = DateUtils.formatDate(calendar.getTime(), yMd);
                    SimpleDateFormat sdf = new SimpleDateFormat(yMd);
                    //1,正常工作日  2,节假日 3,节假日后补班 4,周末
                    List<Integer> list = getIfHoliday(format);
                    int ifHoliday = (int) list.get(0);
                    int week = (int) list.get(1);
                    CalendarInfo calendarInfo = new CalendarInfo();
                    for (CalendarInfo calendarInfo1 : calendarInfoList) {
                        if (sdf.format(calendarInfo1.getDate()).equals(format)) {
                            calendarInfo.setId(calendarInfo1.getId());
                            break;
                        }
                    }
                    calendarInfo.setDate(sdf.parse(format));
                    calendarInfo.setHoliday(ifHoliday);
                    calendarInfo.setWorkDay((ifHoliday == 1 || ifHoliday == 3) ? 1 : 2);
                    calendarInfo.setWeek(week);
                    listCalendar.add(calendarInfo);
                    calendar.add(Calendar.DATE, 1);//在第一天的基础上加1
                }
            }
            if (calendarInfoService.updateBatchById(listCalendar)) {
                return new ResponseResult<Object>().success();
            } else {
                return new ResponseResult<Object>().failure();
            }
        } else {
            //获取12个月
            for (int month = 1; month <= 12; month++) {
                calendar.set(Calendar.MONTH, month - 1);// 设置月份
                calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为当月第一天
                int daySize = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);// 当月最大天数
                for (int i = 0; i < daySize; i++) {
                    String format = DateUtils.formatDate(calendar.getTime(), yMd);
                    SimpleDateFormat sdf = new SimpleDateFormat(yMd);
                    //1,正常工作日  2,节假日 3,节假日后补班 4,周末
                    List<Integer> list = getIfHoliday(format);
                    int ifHoliday = (int) list.get(0);
                    int week = (int) list.get(1);
                    CalendarInfo calendarInfo = new CalendarInfo();
                    calendarInfo.setDate(sdf.parse(format));
                    calendarInfo.setHoliday(ifHoliday);
                    calendarInfo.setWorkDay((ifHoliday == 1 || ifHoliday == 3) ? 1 : 2);
                    calendarInfo.setWeek(week);
                    listCalendar.add(calendarInfo);
                    calendar.add(Calendar.DATE, 1);//在第一天的基础上加1
                }
            }
            if (calendarInfoService.saveBatch(listCalendar)) {
                return new ResponseResult<Object>().success();
            } else {
                return new ResponseResult<Object>().failure();
            }
        }
    }

    @Override
    public ResponseResult<Object> getOtherDeptList() throws CustomException, ApiException {
        List<TaskLog> taskLogList = new ArrayList<>();
        //多家外包公司的人员信息
        for (TokenInfoTO token : getOtherToken()) {
            try {
                List<OapiDepartmentListResponse.Department> dingDeptList = dingDingService.getDepartmentList(token.getToken(), null, null, null);
                List<Dept> deptList = deptService.list(new LambdaQueryWrapper<Dept>().eq(Dept::getCompanyType, token.getType()));
                log.info("更新外包部门定时任务===> dingDeptList: {} ,deptList: {}", dingDeptList, deptList);
                int updateCount = 0;
                int insertCount = 0;
                for (OapiDepartmentListResponse.Department a : dingDeptList) {
                    boolean isUpdate = false;
                    for (Dept b : deptList) {
                        if ((a.getId().toString() + token.getType()).equals(b.getDeptId())) {
                            isUpdate = true;
                            break;
                        }
                    }
                    Dept dept = new Dept();
                    //不同钉钉公司的根部门ID都相同,外包的公司ID加一位数字
                    dept.setDeptId(a.getId().toString() + token.getType());
                    dept.setDeptName(a.getName());
                    dept.setCompanyType(token.getType());
                    if (a.getParentid() != null) {
                        dept.setParentId(a.getParentid().toString());
                    }
                    OapiDepartmentGetResponse oapiDepartmentGetResponse = dingDingService.getDepartmentDetail(a.getId().toString(), token.getToken());
                    dept.setSort(oapiDepartmentGetResponse.getOrder().intValue());
                    dept.setDeptManagerUseridList(oapiDepartmentGetResponse.getDeptManagerUseridList());
                    if (isUpdate) {
                        updateCount += 1;
                        deptService.updateByDeptId(dept);
                    } else {
                        insertCount += 1;
                        deptService.save(dept);
                    }
                }
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.DEPT_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setInsertCount(insertCount);
                taskLog.setUpdateCount(updateCount);
                taskLog.setSuccess(Constant.IsDelete.NO);
                taskLogService.save(taskLog);
                taskLogList.add(taskLog);
                return new ResponseResult<Object>().success(taskLog);
            } catch (Exception e) {
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.DEPT_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setSuccess(Constant.IsDelete.YES);
                taskLogService.save(taskLog);
                e.printStackTrace();
                try {
                    sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.DEPT_TASK_OTHER + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
            }
        }
        return new ResponseResult<Object>().success(taskLogList);
    }

    @Override
    public ResponseResult<Object> getOtherUserList() throws CustomException, ApiException {
        List<TaskLog> taskLogList = new ArrayList<>();
        //多家外包公司的人员信息
        for (TokenInfoTO token : getOtherToken()) {
            try {
                //获取钉钉部门id
                List<OapiDepartmentListResponse.Department> dingDeptList = dingDingService.getDepartmentList(token.getToken(), null, null, null);
                log.info("更新外包用户和部门关联表===> dingDeptList: {} ", dingDeptList);
                int updateCount = 0;
                int insertCount = 0;
                for (OapiDepartmentListResponse.Department a : dingDeptList) {
                    //获取钉钉部门下的用户
                    OapiUserSimplelistRequest oapiUserSimplelistRequest = new OapiUserSimplelistRequest();
                    oapiUserSimplelistRequest.setDepartmentId(a.getId());
                    List<OapiUserSimplelistResponse.Userlist> dingUserList = dingDingService.getUserSimplelist(oapiUserSimplelistRequest, token.getToken());
                    //获取部门下的用户
                    List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, token.getType()));

                    //主公司存在该用户就不插入
                    List<User> userMainList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, Constant.IsDelete.YES));
                    Iterator<OapiUserSimplelistResponse.Userlist> it = dingUserList.iterator();
                    while(it.hasNext()){
                        OapiUserSimplelistResponse.Userlist user = it.next();
                        for (User userMain : userMainList) {
                            if (user.getUserid().equals(userMain.getUserId())) {
                                it.remove();
                            }
                        }
                    }

                    //操作用户表
                    for (OapiUserSimplelistResponse.Userlist dingUser : dingUserList) {
                        boolean isUserUpdate = false;
                        for (User u : userList) {
                            if (dingUser.getUserid().equals(u.getUserId())) {
                                isUserUpdate = true;
                                break;
                            }
                        }
                        DingUserDetailVO dingUserDetailVO = dingDingService.getUserDetailByUserid(token.getToken(), dingUser.getUserid());
                        User user = new User();
                        user.setUnionId(dingUserDetailVO.getUnionid());
                        user.setUserId(dingUserDetailVO.getUserid());
                        user.setUserName(dingUserDetailVO.getName());
                        user.setMobile(dingUserDetailVO.getMobile());
                        user.setEmail(dingUserDetailVO.getEmail());
                        user.setPosition(dingUserDetailVO.getPosition());
                        user.setAvatar(dingUserDetailVO.getAvatar());
                        user.setHiredDate(dingUserDetailVO.getHiredDate());
                        user.setJobNumber(dingUserDetailVO.getJobnumber());
                        user.setIsAdmin(dingUserDetailVO.getIsAdmin().equals(true) ? 1 : 0);
                        user.setIsSenior(dingUserDetailVO.getIsSenior().equals(true) ? 1 : 0);
                        user.setWorkPlace(dingUserDetailVO.getWorkplace());
                        user.setIsResign(Constant.IsDelete.YES);
                        user.setCompanyType(token.getType());
                        if (isUserUpdate) {
                            updateCount += 1;
                            userService.updateUser(user);
                        } else {
                            insertCount += 1;
                            userService.save(user);
                        }
                    }

                    //删除操作用户部门关联表多余的数据
                    List<UserDept> userDeptListDel = userDeptService.list(new LambdaQueryWrapper<UserDept>().eq(UserDept::getDeptId, a.getId().toString() + token.getType()).eq(UserDept::getCompanyType, token.getType()));
                    for (UserDept userDept : userDeptListDel) {
                        boolean delUserDept = false;
                        //操作用户部门关联表
                        for (OapiUserSimplelistResponse.Userlist dingUser : dingUserList) {
                            if (dingUser.getUserid().equals(userDept.getUserId()) && (a.getId().toString() + token.getType()).equals(userDept.getDeptId())) {
                                delUserDept = true;
                                break;
                            }
                        }
                        //删除
                        if (!delUserDept) {
                            updateCount += 1;
                            userDeptService.delUserDept(userDept);
                        }
                    }

                    //获取关联表
                    List<UserDept> userDeptList = userDeptService.list(new LambdaQueryWrapper<UserDept>().eq(UserDept::getCompanyType, token.getType()));

                    //操作用户部门关联表
                    for (OapiUserSimplelistResponse.Userlist dingUser : dingUserList) {
                        boolean isUserDeptUpdate = false;
                        for (UserDept userDept : userDeptList) {
                            if (dingUser.getUserid().equals(userDept.getUserId()) && (a.getId().toString() + token.getType()).equals(userDept.getDeptId())) {
                                isUserDeptUpdate = true;
                                break;
                            }
                        }
                        UserDept userDept = new UserDept();
                        userDept.setUserId(dingUser.getUserid());
                        userDept.setDeptId(a.getId().toString() + token.getType());
                        userDept.setCompanyType(token.getType());
                        if (isUserDeptUpdate) {
                            updateCount += 1;
                            userDeptService.update(userDept, new LambdaQueryWrapper<UserDept>().eq(UserDept::getUserId, dingUser.getUserid()).eq(UserDept::getDeptId, a.getId().toString() + token.getType()));
                        } else {
                            insertCount += 1;
                            userDeptService.save(userDept);
                        }
                    }


                }
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.USER_DEPT_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setInsertCount(insertCount);
                taskLog.setUpdateCount(updateCount);
                taskLog.setSuccess(Constant.IsDelete.NO);
                taskLogService.save(taskLog);
                taskLogList.add(taskLog);
                return new ResponseResult<Object>().success(taskLog);
            } catch (Exception e) {
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.USER_DEPT_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setSuccess(Constant.IsDelete.YES);
                taskLogService.save(taskLog);
                e.printStackTrace();
                try {
                    sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.USER_DEPT_TASK_OTHER + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
            }
        }
        return new ResponseResult<Object>().success(taskLogList);
    }

    @Override
    public ResponseResult<Object> getOtherResignUser() throws CustomException, ApiException {
        List<TaskLog> taskLogList = new ArrayList<>();
        //多家外包公司的人员信息
        for (TokenInfoTO token : getOtherToken()) {
            try {
                Long size = 20L;
                Long offSet = 1L;
                Integer updateCount = 0;
                Integer insertCount = 0;
                //查询所有离职用户的id
                OapiSmartworkHrmEmployeeQuerydimissionResponse.Paginator resignUserList = dingDingService.getEmployeeDimission(offSet, size, token.getToken());
                while (resignUserList.getNextCursor() != null) {
                    offSet += 1;
                    OapiSmartworkHrmEmployeeQuerydimissionResponse.Paginator newResignUserList = dingDingService.getEmployeeDimission(offSet, size, token.getToken());
                    resignUserList.getDataList().addAll(newResignUserList.getDataList());
                    resignUserList.setNextCursor(newResignUserList.getNextCursor());
                }
                //更新离职用户
                List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, token.getType()));
                log.info("更新外包离职员工定时任务===> resignUserList: {} ,userList: {}", resignUserList, userList);
                for (String str : resignUserList.getDataList()) {
                    for (User user : userList) {
                        if (str.equals(user.getUserId())) {
                            updateCount += 1;
                            user.setIsResign(Constant.IsDelete.NO);
                            userService.update(user, new LambdaQueryWrapper<User>().eq(User::getId, user.getId()));
                        }
                    }
                }
                //更新员工类型
                List<User> userLists = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, token.getType()).eq(User::getIsResign, 1));
                //钉钉员工状态获取(userId最多传50个)
                List<User> dingUserLists = new ArrayList<>();
                dingUserLists.addAll(userLists);
                List<User> dingUserLists1;
                List<OapiSmartworkHrmEmployeeListResponse.EmpFieldInfoVO> dingEmployeeList = new ArrayList<>();
                while (CollUtil.isNotEmpty(dingUserLists)) {
                    if (dingUserLists.size() <= 50) {
                        dingUserLists1 = dingUserLists.subList(0, dingUserLists.size());
                    } else {
                        dingUserLists1 = dingUserLists.subList(0, 50);
                    }
                    StringBuilder userString = new StringBuilder();
                    for (User user : dingUserLists1) {
                        userString.append(user.getUserId() + ",");
                    }
                    List<OapiSmartworkHrmEmployeeListResponse.EmpFieldInfoVO> dingEmployee = dingDingService.getHrmEmployeeList(userString.toString(), null, getToken());
                    dingEmployeeList.addAll(dingEmployee);
                    //删除list前50条的数据
                    Iterator<User> iterator = dingUserLists.iterator();
                    int i = 0;
                    while (iterator.hasNext()) {
                        iterator.next();//next（）取出元素
                        if (i <= 49) {
                            iterator.remove(); //remove方法会删除使用next()方法返回 的元素
                        }
                        i++;
                    }
                }
                for (User user : userLists) {
                    for (OapiSmartworkHrmEmployeeListResponse.EmpFieldInfoVO employee : dingEmployeeList) {
                        if (employee.getUserid().equals(user.getUserId())) {
                            boolean isUpdate = false;
                            User user1 = new User();
                            for (OapiSmartworkHrmEmployeeListResponse.EmpFieldVO empField : employee.getFieldList()) {
                                if (empField.getFieldCode().equals("sys01-employeeType")) {
                                    user1.setEmployeeType(empField.getLabel());
                                    updateCount += 1;
                                    isUpdate = true;
                                }
                                if (empField.getFieldCode().equals("sys01-employeeStatus")) {
                                    user1.setEmployeeStatus(empField.getLabel());
                                    isUpdate = true;
                                }
                            }
                            if (isUpdate) {
                                userService.update(user1, new LambdaQueryWrapper<User>().eq(User::getUserId, user.getUserId()));
                            }
                        }
                    }
                }
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.USER_RESIGN_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setInsertCount(insertCount);
                taskLog.setUpdateCount(updateCount);
                taskLog.setSuccess(Constant.IsDelete.NO);
                taskLogService.save(taskLog);
                taskLogList.add(taskLog);
                return new ResponseResult<Object>().success(taskLog);
            } catch (Exception e) {
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.USER_RESIGN_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setSuccess(Constant.IsDelete.YES);
                taskLogService.save(taskLog);
                e.printStackTrace();
                try {
                    sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.USER_RESIGN_TASK_OTHER + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
            }
        }
        return new ResponseResult<Object>().success(taskLogList);
    }

    @Override
    public ResponseResult<Object> getOtherAttendanceList(String time) throws CustomException, ApiException {
        List<TaskLog> taskLogList = new ArrayList<>();
        //多家外包公司的人员信息
        for (TokenInfoTO token : getOtherToken()) {
            try {

                SimpleDateFormat sdfFrom = new SimpleDateFormat(yMdHms);
                SimpleDateFormat sdfEnd = new SimpleDateFormat(yMdHms);
                SimpleDateFormat sdfymd = new SimpleDateFormat(yMd);
                Date dateFrom;
                Date dateEnd;
                if(time == null){
                    //开始时间
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    //往前推1天
                    //calendar.add(Calendar.DATE, -1);
                    dateFrom = calendar.getTime();

                    //结束时间
                    Calendar calendarEnd = Calendar.getInstance();
                    dateEnd = calendarEnd.getTime();
                }else{
                    dateFrom = getStartOfDay(sdfymd.parse(time));
                    dateEnd = getEndOfDay(sdfymd.parse(time));
                }


                List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, token.getType()));
                log.info("更新外包考勤定时任务===> userList: {},dateFrom :{},dateEnd:{}", userList, sdfFrom.format(dateFrom), sdfEnd.format(dateEnd));
                int insertCount = 0;
                int updateCount = 0;
                for (User u : userList) {

                    OapiAttendanceListRequest request = new OapiAttendanceListRequest();
                    request.setWorkDateFrom(sdfFrom.format(dateFrom));
                    request.setWorkDateTo(sdfEnd.format(dateEnd));
                    List<String> str = new ArrayList<>();
                    str.add(u.getUserId());
                    request.setUserIdList(str);
                    request.setOffset(0L);
                    request.setLimit(2L);
                    List<OapiAttendanceListResponse.Recordresult> dingAttendanceList = dingDingService.getAttendanceList(request, token.getToken());

                    if (CollUtil.isNotEmpty(dingAttendanceList)) {

                        UserAttendanceTO userAttendanceTO = new UserAttendanceTO();
                        userAttendanceTO.setUserId(u.getUserId());
                        userAttendanceTO.setUserName(u.getUserName());
                        userAttendanceTO.setCreateDate(new Date());
                        for (OapiAttendanceListResponse.Recordresult dingAttendance : dingAttendanceList) {
                            userAttendanceTO.setDutyDate(dingAttendance.getWorkDate());
                            switch (dingAttendance.getCheckType()) {
                                case "OnDuty":
                                    userAttendanceTO.setOnDutyTimeResult(dingAttendance.getTimeResult());
                                    userAttendanceTO.setOnDuty(dingAttendance.getUserCheckTime());
                                    break;
                                case "OffDuty":
                                default:
                                    userAttendanceTO.setOffDutyTimeResult(dingAttendance.getTimeResult());
                                    userAttendanceTO.setOffDuty(dingAttendance.getUserCheckTime());
                                    break;
                            }
                        }
                        //查询是否有当天的记录
                        SimpleDateFormat sdf = new SimpleDateFormat(yMd);
                        UserAttendance userAttendance = userAttendanceService.getOne(new LambdaQueryWrapper<UserAttendance>().eq(UserAttendance::getUserId, u.getUserId()).eq(UserAttendance::getDutyDate, sdf.format(userAttendanceTO.getDutyDate())));
                        if (null == userAttendance) {
                            insertCount += 1;
                            userAttendanceService.saveUserAttendance(userAttendanceTO);
                        } else {
                            updateCount += 1;
                            userAttendanceTO.setModifyDate(new Date());
                            userAttendanceService.updateUserAttendance(userAttendanceTO);
                        }

                    }

                }
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.ATTENDANCE_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setInsertCount(insertCount);
                taskLog.setUpdateCount(updateCount);
                taskLog.setSuccess(Constant.IsDelete.NO);
                taskLogService.save(taskLog);
                return new ResponseResult<Object>().success(taskLog);
            } catch (Exception e) {
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.ATTENDANCE_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setSuccess(Constant.IsDelete.YES);
                taskLogService.save(taskLog);
                e.printStackTrace();
                try {
                    sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.ATTENDANCE_TASK_OTHER + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
            }
        }
        return new ResponseResult<Object>().success(taskLogList);
    }

    @Override
    public ResponseResult<Object> getOtherLeaveList() throws CustomException, ApiException {
        List<TaskLog> taskLogList = new ArrayList<>();
        //多家外包公司的人员信息
        for (TokenInfoTO token : getOtherToken()) {
            try {
                //开始时间
                Calendar calendar = Calendar.getInstance();
                calendar.set(Calendar.HOUR_OF_DAY, 0);
                calendar.set(Calendar.MINUTE, 0);
                calendar.set(Calendar.SECOND, 0);
                //往前推7天
                calendar.add(Calendar.DATE, -7);
                Date dateFrom = calendar.getTime();
                SimpleDateFormat sdfFrom = new SimpleDateFormat(yMdHms);

                //结束时间
                Calendar calendarEnd = Calendar.getInstance();
                Date dateEnd = calendarEnd.getTime();
                SimpleDateFormat sdfEnd = new SimpleDateFormat(yMdHms);

                Long offSet = 0L;
                Long size = 10L;
                List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, token.getType()));
                log.info("更新外包请假定时任务===> userList: {},dateFrom :{},dateEnd:{}", userList, sdfFrom.format(dateFrom), sdfEnd.format(dateEnd));
                int insertCount = 0;
                for (User u : userList) {
                    OapiAttendanceGetleavestatusRequest request = new OapiAttendanceGetleavestatusRequest();
                    request.setStartTime(sdfFrom.parse(sdfFrom.format(dateFrom)).getTime());
                    request.setEndTime(sdfEnd.parse(sdfFrom.format(dateEnd)).getTime());
                    request.setOffset(offSet);
                    request.setSize(size);
                    request.setUseridList(u.getUserId());
                    OapiAttendanceGetleavestatusResponse.LeaveStatusListVO dingLeave = dingDingService.getLeaveStatus(request, token.getToken());

                    //钉钉接口含有分页,查出所有值
                    while (dingLeave.getHasMore().equals(true)) {
                        request.setSize(size);
                        offSet += 1L;
                        request.setOffset(offSet);
                        OapiAttendanceGetleavestatusResponse.LeaveStatusListVO newDingLeave = dingDingService.getLeaveStatus(request, token.getToken());
                        dingLeave.getLeaveStatus().addAll(newDingLeave.getLeaveStatus());
                        dingLeave.setHasMore(newDingLeave.getHasMore());
                    }

                    //删除当前用户7天前到现在的数据
                    userLeaveService.delLeave(u.getUserId(), dateFrom, dateEnd);

                    if (CollUtil.isNotEmpty(dingLeave.getLeaveStatus())) {
                        List<UserLeave> userLeaveList = new ArrayList<>();
                        for (OapiAttendanceGetleavestatusResponse.LeaveStatusVO leave : dingLeave.getLeaveStatus()) {
                            UserLeave userLeave = new UserLeave();
                            userLeave.setUserId(u.getUserId());
                            userLeave.setUserName(u.getUserName());
                            //时间戳转date
                            SimpleDateFormat sdf = new SimpleDateFormat(yMdHms);
                            Date dateB = new Date(leave.getStartTime());
                            String dateBeginTime = sdf.format(dateB);
                            Date dateE = new Date(leave.getEndTime());
                            String dateEndTime = sdf.format(dateE);

                            userLeave.setLeaveBeginTime(sdf.parse(dateBeginTime));
                            userLeave.setLeaveEndTime(sdf.parse(dateEndTime));
                            userLeaveList.add(userLeave);
                            insertCount += 1;
                        }

                        if (CollUtil.isNotEmpty(userLeaveList)) {
                            userLeaveService.saveBatch(userLeaveList);
                        }
                    }
                }
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.LEAVE_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setInsertCount(insertCount);
                taskLog.setSuccess(Constant.IsDelete.NO);
                taskLogService.save(taskLog);
                taskLogList.add(taskLog);
                return new ResponseResult<Object>().success(taskLog);
            } catch (Exception e) {
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.LEAVE_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setSuccess(Constant.IsDelete.YES);
                taskLogService.save(taskLog);
                e.printStackTrace();
                try {
                    sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.LEAVE_TASK_OTHER + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
            }
        }
        return new ResponseResult<Object>().success(taskLogList);
    }

    @Override
    public ResponseResult<Object> getOtherWorkDailyList(String time) throws CustomException, ApiException {
        List<TaskLog> taskLogList = new ArrayList<>();
        //多家外包公司的人员信息
        for (TokenInfoTO token : getOtherToken()) {
            try {
                SimpleDateFormat sdfFrom = new SimpleDateFormat(yMdHms);
                SimpleDateFormat sdfEnd = new SimpleDateFormat(yMdHms);
                SimpleDateFormat sdfymd = new SimpleDateFormat(yMd);
                Date dateFrom;
                Date dateEnd;
                if(time == null){
                    //开始时间
                    Calendar calendar = Calendar.getInstance();
                    calendar.set(Calendar.HOUR_OF_DAY, 0);
                    calendar.set(Calendar.MINUTE, 0);
                    calendar.set(Calendar.SECOND, 0);
                    //往前推1天
                    calendar.add(Calendar.DATE, -1);
                    dateFrom = calendar.getTime();

                    //结束时间
                    Calendar calendarEnd = Calendar.getInstance();
                    dateEnd = calendarEnd.getTime();
                }else{
                    dateFrom = getStartOfDay(sdfymd.parse(time));
                    dateEnd = getEndOfDay(sdfymd.parse(time));
                }

                int insertCount = 0;
                int updateCount = 0;
                OapiReportListRequest request = new OapiReportListRequest();
                request.setStartTime(sdfFrom.parse(sdfFrom.format(dateFrom)).getTime());
                request.setEndTime(sdfEnd.parse(sdfFrom.format(dateEnd)).getTime());
                request.setTemplateName(wordTemplate);
                request.setCursor(0L);
                request.setSize(20L);
                OapiReportListResponse.PageVo dingWorkDaily = dingDingService.getReportList(request, token.getToken());
                while (dingWorkDaily.getHasMore().equals(true)) {
                    request.setCursor(dingWorkDaily.getNextCursor());
                    OapiReportListResponse.PageVo newDingWorkDaily = dingDingService.getReportList(request, token.getToken());
                    dingWorkDaily.setHasMore(newDingWorkDaily.getHasMore());
                    dingWorkDaily.setNextCursor(newDingWorkDaily.getNextCursor());
                    dingWorkDaily.getDataList().addAll(newDingWorkDaily.getDataList());
                }
                List<User> userList = userService.list(new LambdaQueryWrapper<User>().eq(User::getCompanyType, token.getType()));
                log.info("更新外包用户日志信息任务===> userList: {},dingWorkDaily: {},dateFrom :{},dateEnd:{}", userList, dingWorkDaily, sdfFrom.format(dateFrom), sdfEnd.format(dateEnd));
                if (CollUtil.isNotEmpty(dingWorkDaily.getDataList())) {
                    //1.在插入日志表时，根据工作时间，项目编号，去项目节点周期表pro_node_date中查找该日志所处在的项目节点id，并更新到日志表user_workdaily_log的项目节点id，nodeId字段。
                    //2.再根据用户id，项目编号，节点id在项目人员分配表中获取项目角色ID：proroleId，并更新到日志表user_workdaily_log的项目角色ID，proroleId字段。
                    for (OapiReportListResponse.ReportOapiVo dingWork : dingWorkDaily.getDataList()) {
                        for (User u : userList) {
                            if (u.getUserId().equals(dingWork.getCreatorId())) {
                                WorkLogDetailTO workLogDetailTO = new WorkLogDetailTO();
                                //获取Contents值并且匹配
                                for (OapiReportListResponse.JsonObject contents : dingWork.getContents()) {
                                    //工作日期
                                    if (contents.getKey().equals(systemVariable.getWorkDate())) {
                                        SimpleDateFormat sdf = new SimpleDateFormat(yMd);
                                        workLogDetailTO.setWorkDate(sdf.parse(contents.getValue()));
                                    }
                                    //投入人天
                                    else if (contents.getKey().equals(systemVariable.getPutinDaily())) {
                                        workLogDetailTO.setPutinDaily(new BigDecimal(contents.getValue()));
                                    }
                                    //所属部门
                                    else if (contents.getKey().equals(systemVariable.getWorkDept())) {
                                        workLogDetailTO.setDeptName(contents.getValue());
                                    }
                                    //项目
                                    else if (contents.getKey().equals(systemVariable.getProName())) {
                                        workLogDetailTO.setProName(contents.getValue());
                                    }
                                    //开发节点
                                    else if (contents.getKey().equals(systemVariable.getNodeName())) {
                                        workLogDetailTO.setDevPoint(contents.getValue());
                                    }
                                    //绩效人天
                                    else if (contents.getKey().equals(systemVariable.getPerformanceDaily())) {
                                        workLogDetailTO.setPerformanceDaily(new BigDecimal(contents.getValue()));
                                    }
                                    //今日工作
                                    else if (contents.getKey().equals(systemVariable.getDailyLog())) {
                                        workLogDetailTO.setDailyLog(contents.getValue());
                                    }
                                    //备注
                                    else if (contents.getKey().equals(systemVariable.getRemark())) {
                                        workLogDetailTO.setRemark(contents.getValue());
                                    }
                                    //明日计划
                                    else if (contents.getKey().equals(systemVariable.getTomorrowPlan())) {
                                        workLogDetailTO.setTomorrowPlan(contents.getValue());
                                    }
                                }

                                UserWorkdailyLog userWorkdailyLog = new UserWorkdailyLog();
                                userWorkdailyLog.setUserId(u.getUserId());
                                userWorkdailyLog.setUserName(u.getUserName());
                                if (null != deptService.getOne(new LambdaQueryWrapper<Dept>().eq(Dept::getDeptName, workLogDetailTO.getDeptName()).eq(Dept::getCompanyType, token.getType()))) {
                                    Dept dept = deptService.getOne(new LambdaQueryWrapper<Dept>().eq(Dept::getDeptName, workLogDetailTO.getDeptName()).eq(Dept::getCompanyType, token.getType()));
                                    userWorkdailyLog.setUserDept(dept.getDeptId());
                                    userWorkdailyLog.setDeptName(dept.getDeptName());
                                }
                                if (StringUtils.isNotBlank(workLogDetailTO.getProName())) {
                                    try {
                                        userWorkdailyLog.setProNo(workLogDetailTO.getProName().substring(workLogDetailTO.getProName().indexOf("(") + 1, workLogDetailTO.getProName().lastIndexOf(")")));//项目编号
                                        userWorkdailyLog.setProName(workLogDetailTO.getProName().substring(0, workLogDetailTO.getProName().lastIndexOf("(")));//项目名称
                                    } catch (Exception e) {
                                        sendMailUtils.send(getInfo().getSendTo(), "日志模版中,项目 " + workLogDetailTO.getProName() + " 名称格式有误，请检查日志模版中项目选项的配置！",
                                                Constant.TaskMessage.DAILY_LOG_FAILURE,
                                                false, null);
                                        continue;
                                    }
                                }
                                if (null != proBaseInfoService.getOne(new LambdaQueryWrapper<ProBaseInfo>().eq(ProBaseInfo::getProCode, userWorkdailyLog.getProNo()))) {
                                    ProBaseInfo proBaseInfo = proBaseInfoService.getOne(new LambdaQueryWrapper<ProBaseInfo>().eq(ProBaseInfo::getProCode, userWorkdailyLog.getProNo()));
                                    if (null != proNodeDateService.getProNodeId(proBaseInfo.getId(), workLogDetailTO.getWorkDate())) {
                                        ProNodeDate proNodeDate = proNodeDateService.getProNodeId(proBaseInfo.getId(), workLogDetailTO.getWorkDate());
                                        userWorkdailyLog.setNodeId(Long.valueOf(proNodeDate.getProNodeId()));//项目节点
                                        ProNode proNode = proNodeService.getOne(new LambdaQueryWrapper<ProNode>().eq(ProNode::getId, proNodeDate.getProNodeId()));
                                        userWorkdailyLog.setNodeName(proNode.getNodeName());//项目节点名称
                                    }
                                    if (null != proAssignmentService.getOne
                                            (new LambdaQueryWrapper<ProAssignment>().eq(ProAssignment::getUserId, userWorkdailyLog.getUserId()).
                                                    eq(ProAssignment::getProId, proBaseInfo.getId()).
                                                    eq(ProAssignment::getNodeId, userWorkdailyLog.getNodeId()))) {
                                        ProAssignment proAssignment = proAssignmentService.getOne
                                                (new LambdaQueryWrapper<ProAssignment>().eq(ProAssignment::getUserId, userWorkdailyLog.getUserId()).
                                                        eq(ProAssignment::getProId, proBaseInfo.getId()).
                                                        eq(ProAssignment::getNodeId, userWorkdailyLog.getNodeId()));
                                        userWorkdailyLog.setProroleId(proAssignment.getProroleId());//项目角色
                                    }
                                } else {
                                    if (!userWorkdailyLog.getProNo().equals("OTHER0001")) {
                                        sendMailUtils.send(getInfo().getSendTo(), "日志模版中" + workLogDetailTO.getProName() + "不存在，请检查日志模版中项目选项的配置！",
                                                Constant.TaskMessage.DAILY_LOG_FAILURE,
                                                false, null);
                                        continue;
                                    }
                                }
                                userWorkdailyLog.setDevPoint(workLogDetailTO.getDevPoint());
                                userWorkdailyLog.setWorkDate(workLogDetailTO.getWorkDate());
                                userWorkdailyLog.setPutinDaily(workLogDetailTO.getPutinDaily());
                                userWorkdailyLog.setPerformanceDaily(workLogDetailTO.getPerformanceDaily());
                                userWorkdailyLog.setDailyLog(workLogDetailTO.getDailyLog());
                                userWorkdailyLog.setRemark(workLogDetailTO.getRemark());
                                userWorkdailyLog.setTomorrowPlan(workLogDetailTO.getTomorrowPlan());
                                userWorkdailyLog.setTemplateName(dingWork.getTemplateName());
                                userWorkdailyLog.setSubmitTime(new Date(dingWork.getCreateTime()));

                                //查询是否有记录
                                int record = userWorkdailyLogService.selectCount(userWorkdailyLog);
                                if (record == 0) {
                                    insertCount += 1;
                                    userWorkdailyLogService.save(userWorkdailyLog);
                                } else {
                                    int isReview = userWorkdailyLogService.isReview(userWorkdailyLog);
                                    if (isReview == 0) {
                                        updateCount += 1;
                                        userWorkdailyLogService.update(userWorkdailyLog, new LambdaQueryWrapper<UserWorkdailyLog>().eq(UserWorkdailyLog::getUserId,userWorkdailyLog.getUserId()).eq(UserWorkdailyLog::getSubmitTime, userWorkdailyLog.getSubmitTime()));
                                    }
                                }
                            }
                        }
                    }

                }

                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.WORK_DAILY_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setInsertCount(insertCount);
                taskLog.setUpdateCount(updateCount);
                taskLog.setSuccess(Constant.IsDelete.NO);
                taskLogService.save(taskLog);
                return new ResponseResult<Object>().success(taskLog);
            } catch (Exception e) {
                TaskLog taskLog = new TaskLog();
                taskLog.setTaskName(Constant.TaskName.WORK_DAILY_TASK_OTHER);
                taskLog.setTaskTime(new Date());
                taskLog.setSuccess(Constant.IsDelete.YES);
                taskLogService.save(taskLog);
                e.printStackTrace();
                try {
                    sendMailUtils.send(getInfo().getSendTo(), Constant.TaskName.WORK_DAILY_TASK_OTHER + Constant.TaskMessage.FAILURE, Constant.TaskMessage.TASK_FAILURE, false, null);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                return new ResponseResult<Object>().failure(Constant.ErrorCode.SYSTEM_ERROR, Constant.ErrorMessage.DING_ERROR, taskLog);
            }
        }
        return new ResponseResult<Object>().success(taskLogList);
    }


}
